package com.example.smartmedicalsystem.controller;

import com.example.smartmedicalsystem.entity.*;
import com.example.smartmedicalsystem.repository.*;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/diagnosis")
@RequiredArgsConstructor
public class DiagnosisController {
    private final AppointmentRepository appointmentRepository;
    private final MedicalRecordRepository medicalRecordRepository;
    private final MessageRepository messageRepository;

    // DiagnosisController.java 修正
    @PostMapping("/{appointmentId}/confirm")
    public ResponseEntity<?> confirmAppointment(@PathVariable Long appointmentId) {
        Appointment appointment = appointmentRepository.findById(appointmentId)
                .orElseThrow(() -> new RuntimeException("预约不存在"));

        // 改为使用CONFIRMED状态
        appointment.setStatus(Appointment.Status.CONFIRMED);
        appointmentRepository.save(appointment);

        // 发送消息
        Message msg = new Message();
        msg.setContent("您的预约已确认，诊断即将开始");
        msg.setReceiver(appointment.getPatient());
        messageRepository.save(msg);

        return ResponseEntity.ok().build();
    }}